package com.travelparadise.dao;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

import com.travelparadise.domain.Vol;

public class VolDaoHibernate implements VolDao {

	HibernateTemplate hibernateTemplate = null;
	public void setSessionFactory(SessionFactory session){
		hibernateTemplate = new HibernateTemplate(session,true);
		
	}
	
	@Override
	@Transactional
	public Vol getById(int id) {
		//HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
		Vol vol = (Vol) hibernateTemplate.get(com.travelparadise.domain.Vol.class, id);
		return vol;
	}

	@Override
	@Transactional
	public Collection<Vol> searchByNameDateArrivee(String nomVilleArrivee) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional
	public Collection<Vol> searchByNameDateDepart(String nomVilleDepart) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional
	public Collection<Vol> searchByNameVilleArrivee(String nomVilleArrivee) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional
	public Collection<Vol> searchByNameVilleDepart(String nomVilleDepart) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional
	public Collection<Vol> searchByNameVilleDepartAndVilleArriveeAndDateDepart(
			String nomVilleDepart, String nomVilleArrivee, Date dateDepart) {
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String date = "";
		date = sdf.format(dateDepart);
		
		String reqHQL = "select vol from Vol as vol where vol.dateDepart='"+date+"' and vol.depart.id='"+nomVilleDepart+"' and vol.arrivee.id='"+nomVilleArrivee+"'";
		Collection<Vol> vols = hibernateTemplate.find(reqHQL);
		return vols;
	}
	
	

}
